package com.czl.module_work.view

import android.content.Context
import android.widget.TextView
import com.cooltechworks.views.shimmer.ShimmerRecyclerView
import com.czl.module_work.R
import com.czl.module_work.adapter.InviteTypeAdapter
import com.lxj.xpopup.core.BottomPopupView

class InviteTypePop(val list: ArrayList<String>, context: Context) : BottomPopupView(context) {
    private var mListener: (String) -> Unit = {}

    fun setFilterResultListener(listener: (String) -> Unit) {
        this.mListener = listener
    }

    override fun getImplLayoutId(): Int = R.layout.work_dialog_invite_type

    override fun initPopupContent() {
        super.initPopupContent()
        val recyclerView = findViewById<ShimmerRecyclerView>(R.id.ry_common)

        val mAdapter = InviteTypeAdapter()
        recyclerView.adapter = mAdapter
        mAdapter.setNewInstance(list)

        mAdapter.setOnItemClickListener { adapter, view, position ->
            mAdapter.oldIndex =mAdapter.selectIndex
            mAdapter.selectIndex = position
            mAdapter.notifyItemChanged(position)
            mAdapter.notifyItemChanged(mAdapter.oldIndex)
//            mAdapter.notifyDataSetChanged()
        }

        findViewById<TextView>(R.id.tv_confirm).setOnClickListener {
            dismiss()
            mListener.invoke(
                if (list.size > mAdapter.selectIndex) {
                    list[mAdapter.selectIndex]
                } else {
                    ""
                }
            )
        }
        findViewById<TextView>(R.id.tv_cancel).setOnClickListener {
            dismiss()
        }
    }
}